package com.amit.struts;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;


public class JDBCEmployeeDAO implements EmployeeDAO {

	@Override
	public EmployeeTO verifyEmployee(String un, String pw) {
		
		EmployeeTO eto=null;
		Connection con=null;
		PreparedStatement ps=null;
		ResultSet rs=null;
		
		try
		{
			con=JDBCUtil.getConnection();
	ps=con.prepareStatement("select * from employees where username=? and password=?");
	
	ps.setString(1, un);
	ps.setString(2, pw);
	rs=ps.executeQuery();
	
	if(rs.next())
	{
		eto=new EmployeeTO();
		eto.setEmpId(rs.getString(1));
		eto.setEname(rs.getString(2));
		eto.setEmail(rs.getString(3));
		eto.setPhone(rs.getString(4));
		eto.setRole(rs.getString(5));
		eto.setUsername(rs.getString(6));
		eto.setPassword(rs.getString(7));
		eto.setStatus(rs.getString(8));
		
	}
		}
		
		catch (Exception e) {
			
			e.printStackTrace();
			
		}
		
		finally
		{
			JDBCUtil.cleanup(con, ps, rs);
		}
		
		return eto;
	}

}
